/*
 * Copyright (c) 2006, Bob Breznak
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *    * Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *    
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 */
package com.iisageek.client;

import java.util.Date;
import com.iisageek.client.widgets.xml.Node;

/**
 * All information associated with a member.
 * 
 * 
 * @TODO add a contact class and then load the client info from there
 * @author Bob Breznak
 *
 */
public class Member {
	public final String FIRST_NAME = "first";
	public final String LAST_NAME = "last";
	public final String STATUS = "status";

	private Node root;
	
	/**
	 * Member
	 * 
	 * make a new member with the given XML structure
	 * 
	 * @param root (Node) the XML structure of a member
	 */
	public Member(Node root) {
		this.root = root;
	}
	
	/**
	 * isOfficer
	 * 
	 * returns True if the member is an officer
	 * 
	 * @return boolean
	 */
	public boolean isOfficer() {
		if(getStatus().equalsIgnoreCase("President") || getStatus().equalsIgnoreCase("Vice-President") ||
				getStatus().equalsIgnoreCase("Technical Director") || getStatus().equalsIgnoreCase("Head Projectionist") ||
				getStatus().equalsIgnoreCase("Treasurer") || getStatus().equalsIgnoreCase("Secretary") ||
				getStatus().equalsIgnoreCase("Webmaster")) {
			return true;
		}
		return false;
	}
	
	/**
	 * getID
	 * 
	 * returns the user's id
	 * 
	 * @return int
	 */
	public int getID() {
		return Integer.parseInt(root.getAttribute("id"));
	}
	
	/**
	 * getStatus
	 * 
	 * return the status of a member (i.e. active, alum)
	 *
	 * @return String
	 */
	public String getStatus() {
		return root.getAttribute("status");
	}
	
	/**
	 * getFirstName
	 * 
	 * returns the first name of the member
	 * 
	 * @return String
	 */
	public String getFirstName() {
		return root.getChild("first").getText();
	}
	
	/**
	 * getLastName
	 * 
	 * returns the last name of the member
	 * 
	 * @return String
	 */
	public String getLastName() {
		return  root.getChild("last").getText();
	}
	
	/**
	 * getEmail
	 * 
	 * returns the email of the member
	 * 
	 * @return String
	 */
	public String getEmail() {
		return root.getChild("email").getText();
	}
	
	/**
	 * getAddress
	 * 
	 * return the address of the member
	 * 
	 * @return String
	 */
	public String getAddress() {
		return root.getChild("address").getText();
	}
	
	/**
	 * getPhone
	 * 
	 * returns the phone number of the member
	 * 
	 * @return String 
	 */
	public String getPhone() {
		return root.getChild("phone").getText();
	}
	
	/**
	 * getYear
	 * 
	 * returns the member's projected graduation year
	 * 
	 * @return int
	 */
	public int getYear() {
		return Integer.parseInt(root.getChild("year").getText());
	}
	
	/**
	 * getJoin
	 * 
	 * returns the date the member joined
	 * 
	 * @return Date
	 */
	public Date getJoin() {
		String str = root.getChild("email").getText();
		return new Date(Integer.parseInt(str.split(":")[0])-1900,
				        Integer.parseInt(str.split(":")[1])-1,
				        Integer.parseInt(str.split(":")[2]));
				
	}
	
	/**
	 * getPhoto
	 * 
	 * returns the relitive path to the photo of the member
	 * 
	 * @return String
	 */
	public String getPhoto() {
		return root.getChild("image").getText();
	}
	
	/**
	 * getWPIID
	 * 
	 * returns the member's WPI ID
	 * 
	 * @return String
	 */
	public String getWPIID() {
		return root.getChild("wpiid").getText();
	}
	
	/**
	 * getHours
	 * 
	 * returns the member's cumulative hours
	 * 
	 * @return float
	 */
	public float getHours() {
		return Float.parseFloat(root.getChild("hours").getText());
	}
}
